// pages/index/index.js

Page({

        /**
         * 页面的初始数据
         */
        data: {
                latitude: "",
                longitude: "",
                gongneng: [{
                                id: "开始施工",
                                icon: "https://6d79-mybiyesheji-1g9dugc1e05b04c4-1309023553.tcb.qcloud.la/icon/%E9%80%9A%E8%AE%AF%E5%BD%95.png?sign=f1fb2552c88fb4cffb929f9105f328ce&t=1669710016",
                                tind: "shigongjishi"
                        },
                        {
                                id: "设备信息",
                                icon: "https://6d79-mybiyesheji-1g9dugc1e05b04c4-1309023553.tcb.qcloud.la/icon/%E5%AE%89%E5%85%A8%E5%B8%BD.png?sign=a421eb302818a6528f26aacdf8eadbd7&t=1669710109",
                                tind: "shebeixinxi",
                                donghua: "touch0"
                        },
                        {
                                id: "派单信息",
                                icon: "https://6d79-mybiyesheji-1g9dugc1e05b04c4-1309023553.tcb.qcloud.la/icon/%E8%AE%A2%E5%8D%95.png?sign=b27cc688583cecacda7e949da72122c4&t=1669710158",
                                tind: "paidanxinxi"
                        },
                        {
                                id: "发起任务",
                                icon: "https://6d79-mybiyesheji-1g9dugc1e05b04c4-1309023553.tcb.qcloud.la/icon/%E4%BB%BB%E5%8A%A1.png?sign=29bb548bd81aa28ad04855e9d84563a4&t=1669710197",
                                tind: "faqirenwu"
                        },
                ],
                tap: [{
                                id: "任务",
                                tind: "renwu"
                        },
                        {
                                id: "我的",
                                tind: "myjump"
                        }
                ],
                tianqi: [],
                city: [],
                yonghuming: null,
                cityicon: "https://6d79-mybiyesheji-1g9dugc1e05b04c4-1309023553.tcb.qcloud.la/icon/%E5%BB%BA%E7%AD%91_%E9%AB%98%E6%A5%BC.png?sign=88b84f915dc47a6df1cc45a68635b417&t=1669700729",
                tempicon: "https://6d79-mybiyesheji-1g9dugc1e05b04c4-1309023553.tcb.qcloud.la/icon/%E6%B0%94%E6%B8%A9-%E9%AB%98%E6%B8%A9.png?sign=62b40a0b048116c2f78ba2037a4db187&t=1669700829",
                tianqiicon: "https://6d79-mybiyesheji-1g9dugc1e05b04c4-1309023553.tcb.qcloud.la/icon/%E5%A4%A9%E6%B0%94.png?sign=5c1d19f24f838fe6cbb85e2826052904&t=1669700874",
                dafengicon: "https://6d79-mybiyesheji-1g9dugc1e05b04c4-1309023553.tcb.qcloud.la/icon/%E9%A3%8E%E5%90%91%E6%A0%87.png?sign=2b6b657245a21e5ca42a1ae53516ba87&t=1669701007",
                animationData: {},
                donghua: {},
                toplink: {}
        },

        /**
         * 生命周期函数--监听页面加载
         */
        onLoad(options) {
                wx.showToast({
                  title: '通讯中...',
                  icon:"loading"
                })
                let that = this
                /**创建 菜单的动画实例 */
                this.animationData = wx.createAnimation({
                        duration: 600,
                        timingFunction: 'ease'
                })
                /**创建 天气预告动画实例 */
                this.donghua = wx.createAnimation({
                        duration: 200,
                        timingFunction: 'ease'
                })
                /**创建 顶部动画实例 */
                this.toplink = wx.createAnimation({
                        duration: 400,
                        timingFunction: 'ease'
                })
                console.log(options);
                /**绑定和格式化经度和纬度的数据 */
                this.setData({
                        latitude: Math.floor(options.latitude * 100) / 100,
                        longitude: Math.floor(options.longitude * 100) / 100,
                        yonghuming: options.userName
                })
                console.log()
                let jingdu = this.data.latitude
                let weidu = this.data.longitude
                console.log(jingdu, weidu)
                /**格式化api的链接地址 */
                let link0 = 'https://devapi.qweather.com/v7/weather/now?location=' + weidu + ',' + jingdu + '&key=44c284610bb9423aa3a129e9182a7407'
                let link1 = 'https://geoapi.qweather.com/v2/city/lookup?location=' + weidu + ',' + jingdu + '&key=44c284610bb9423aa3a129e9182a7407'
                console.log(link0)
                /**接入api的大小 */
                wx.request({
                                url: link0,
                                success(res) {
                                        that.setData({
                                                tianqi: res.data.now
                                        })
                                        console.log("天气信息为:", that.data.tianqi)
                                        if (that.data.tianqi.temp >= 30) {
                                                wx.showModal({
                                                        title: "高温天气",
                                                        showCancel: false,
                                                        content: "“戴帽守护”团队提醒您!请注意高温防护，谨防户外就业中暑和热射病对您身体健康的危害！"
                                                })
                                        } 
                                        if (that.data.tianqi.text & '雨' != 0) {
                                                wx.showModal({
                                                        title: "雷雨天气",
                                                        showCancel: false,
                                                        content: "“戴帽守护”团队提醒您!请注意雷雨天气，谨防户外就业中积水、坑洼里面的潜在危险，警惕防雷防洪！"
                                                })
                                        }
                                }
                        }),
                        wx.request({
                                url: link1,
                                success(res) {
                                        console.log(res)
                                        that.setData({
                                                city: res.data.location[0]
                                        })
                                        console.log("城市信息为：", that.data.city.name)
                                }
                        })


        },

        /**
         * 生命周期函数--监听页面初次渲染完成
         */
        onReady() {

                this.toplink.translateY(-100).step()
                this.toplink.translateY(0).step()
                /***天气预告的动画实例 */
                this.donghua.scale(1.5, 2).step()
                this.donghua.scale(1, 1).step()
                /***菜单的动画实例 */
                this.animationData.translateX(-30).step()
                this.animationData.translateX(0).step()
                /**动画实例导入 */
                this.setData({
                        animationData: this.animationData.export(),
                        donghua: this.donghua.export(),
                        toplink: this.toplink.export()
                })
        },

        /**
         * 生命周期函数--监听页面显示
         */
        onShow: function () {

        },

        /**
         * 生命周期函数--监听页面隐藏
         */
        onHide() {

        },

        /**
         * 生命周期函数--监听页面卸载
         */
        onUnload() {

        },

        /**
         * 页面相关事件处理函数--监听用户下拉动作
         */
        onPullDownRefresh() {

        },

        /**
         * 页面上拉触底事件的处理函数
         */
        onReachBottom() {

        },

        /**
         * 用户点击右上角分享
         */
        onShareAppMessage() {

        },
        /**
         * 用户我的页面跳转
         */
        myjump() {
                wx.navigateTo({
                        url: '/pages/my/my?city'
                })
                wx.showToast({
                        title: '加载中',
                        icon: "loading"
                })
        },
        shigongjishi() {
                wx.navigateTo({
                        url: '/pages/jishiqi/jishiqi',
                })
        },
        faqirenwu() {
                wx.navigateTo({
                        url: '/pages/faqi/faqi',
                })
        },
        shebeixinxi() {
                wx.navigateTo({
                        url: '/pages/shebei/shebei',
                })
        },
        chakantianqi() {
                let that = this;
                /**天气信息 */
                let text = "更新时间为：" + that.data.tianqi.obsTime +"\n" +"气温:" + that.data.tianqi.
                temp +"度\n" + "当前天气为：" + that.data.tianqi.text + "\n" + "当前降水量：" +that.data.tianqi.precip +"mm/h\n" + "当前风向：" + that.data.tianqi.windDir+ "\n" + "当前风速："
                + that.data.tianqi.windSpeed + "km/h\n" + "当前能见度：" + that.data.tianqi.vis + "km\n"+
                "\n戴帽守护\n提醒您\n施工过程中注意天气信息，谨防恶劣天气和高温环境的危害。\n户外施工谨防“中暑”与“热射病”对身体的危害！" + "\n\n数据来源：和风天气API"
                /**点击显示 */
                wx.showModal({
                        cancelColor: 'cancelColor',
                        title: "查看天气",
                        showCancel: false,
                        content: text
                })
        },
        tuanduijies(){
                wx.showModal({
                        cancelColor: 'cancelColor',
                        title: "戴帽守护团队",
                        showCancel: false,
                        content: "戴帽守护团队-广州南方学院高校团队，成立于2024年。由学生团队独立自主研发应用于施工人员的智能安全头盔系统。\n  \n产品融合了“物联网”、“传感器”、“电气自动化”、“人工智能”、“大数据分析”、“GPS北斗定位”等智能学科。\n\n“戴帽守护”--致力于让施工环境更美好！\n\n合作邮箱\n 849631113@qq.com--韩同学\n"
                })
        },
        renwu(){
                wx.showToast({
                  title: '暂不开放...',
                  icon:'error'
                })
        },
        paidanxinxi(){
                wx.showToast({
                  title: '暂不开放...',
                  icon:'error'
                })
        }

})